package com.song.book.controller;

import com.song.book.pojo.Book;
import com.song.book.service.BookService;
import entity.Result;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @Author 宋伟宁
 * @Date 2024/1/5
 * @Version 1.0
 **/
@RestController
@RequestMapping("/book")
public class BookController {
    @Resource
    private BookService bookService;

    @GetMapping("/")
    public Result findBooks()  {
        return new Result(200, "查询成功", true,bookService.findBooks());
    }

    @GetMapping("/{id}")
    public Result findBookById(@PathVariable("id") Long id)  {
        return new Result(200, "查询成功", true,bookService.findBookById(id));
    }

    @PostMapping("/")
    public Result save(@RequestBody Book book) {
        return new Result(200, "保存成功", true, bookService.saveBook(book));
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable("id") Long id) {
        return new Result(200, "删除成功", true, bookService.deleteBook(id));
    }
}
